﻿using System;
using System.Data;
using Model.Data;
using Model;
using DataAccess;
using BusinessLogic.BusinessRules;


namespace BusinessLogic.ClassFactory
{
    /// <summary>
    /// TemplateFactory 的摘要说明。
    /// </summary>
    public class TemplateFactory : BaseFactory
    {
        public TemplateFactory()
            : base()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public TemplateFactory(DBManager l_DBManager)
            : base(l_DBManager)
        {
        }
        public Template NewInstance()
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            Template objTemplate = new Template(this.m_Manager, l_Access);
            objTemplate.NewDataSet();
            objTemplate.SelectRow(0);
            return objTemplate;
        }

        public int Delete(string intTemplateID)
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            return l_Access.Delete(intTemplateID);
        }

        public Template CreatorBySql(string Sql)
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            Template objTemplate = new Template(this.m_Manager, l_Access);
            DataSet l_ds = new TemplateData();
            if (l_Access.QueryBySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objTemplate.SetDataSet(l_ds);
            objTemplate.SelectRow(0);
            return objTemplate;
        }

        public Template CreatorByFullSql(string Sql)
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            Template objTemplate = new Template(this.m_Manager, l_Access);
            DataSet l_ds = new TemplateData();
            if (l_Access.QueryByQuerySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objTemplate.SetDataSet(l_ds);
            objTemplate.SelectRow(0);
            return objTemplate;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="intTemplateID"></param>
        /// <returns></returns>
        public Template Creator(int intTemplateID)
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            Template objTemplate = new Template(this.m_Manager, l_Access);
            DataSet l_ds = new TemplateData();
            if (l_Access.QueryByID(ref l_ds, intTemplateID) < 1)
            {
                return null;
            }
            objTemplate.SetDataSet(l_ds);
            objTemplate.SelectRow(0);
            return objTemplate;
        }

        public Template Creator()
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            Template objTemplate = new Template(this.m_Manager, l_Access);
            DataSet l_ds = new TemplateData();
            if (l_Access.QueryAll(ref l_ds) < 1)
            {
                return null;

            }
            objTemplate.SetDataSet(l_ds);
            objTemplate.SelectRow(0);
            return objTemplate;
        }

        public int Delete(int intTemplateID)
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            return l_Access.Delete(intTemplateID);
        }
        public int DeleteWhere(string where)
        {
            TemplateAccess l_Access = new TemplateAccess(m_Manager);
            return l_Access.DeleteWhere(where);
        }
    }
}
